﻿namespace Infrastructure.Utils
{
    public class MPHelper
    {
        /// <summary>
        /// 根据小程序用户code获取OpenID
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string GetOpenId(string appid, string secret, string code)
        {
            var uri = $"https://api.weixin.qq.com/sns/jscode2session?appid={appid}&secret={secret}&js_code={code}&grant_type=authorization_code";
            var client = new HttpClient();
            var res = client.GetAsync(uri).Result;
            var resContent = res.Content.ReadAsStringAsync().Result;
            return resContent;
        }
    }

    public class MpOpenIdDTO
    {
        public string Code { get; set; }
        public string AppID { get; set; }
        public string Secret { get; set; }
    }
}